﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess.Operate
{
    public class DA_Report_Change_AreaUnit_Adjust_Inherit:SqlInteractionBase
    {
        public DataSet FindAreaUnitAdjusts(string AreaUnit_MainID)
        {

            string sSql = "select Report_Change_AreaUnit_AdjustID from t_Report_Change_AreaUnit_Adjust where Report_Change_AreaUnit_MainID='" + AreaUnit_MainID + "'";
            SqlCommand cmdToExecute = new SqlCommand();
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
            DataSet ds = new DataSet();

            cmdToExecute.CommandText = sSql;
            cmdToExecute.CommandType = CommandType.Text;

            try
            {
                cmdToExecute.Connection = _mainConnection;
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                adapter.Fill(ds);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Close();
                }

                cmdToExecute.Dispose();

                adapter.Dispose();
            }

            return ds;
        }

        public bool DeleteByMainID(string AreaUnit_MainID)
        {
            string sSql = "delete from t_Report_Change_AreaUnit_Adjust where Report_Change_AreaUnit_MainID='" + AreaUnit_MainID + "'";
            SqlCommand cmdToExecute = new SqlCommand();


            cmdToExecute.CommandText = sSql;
            cmdToExecute.CommandType = CommandType.Text;

            try
            {
                cmdToExecute.Connection = _mainConnection;
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                _rowsAffected = cmdToExecute.ExecuteNonQuery();
                return true;

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Close();
                }

                cmdToExecute.Dispose();


            }

         
        }
    }
}
